package com.example.mylitepaldemo;

//import static com.example.mylitepaldemo.composeui.TestShowUiKt.testShow;

import androidx.appcompat.app.AppCompatActivity;
import androidx.compose.ui.platform.ComposeView;

import android.app.Application;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.example.mylitepaldemo.composeui.TestShowUi;
import com.example.mylitepaldemo.database.HistoryRecord;

import org.jetbrains.annotations.NotNull;
import org.litepal.LitePal;
import org.litepal.tablemanager.Connector;

import java.util.List;

public class MainActivity extends AppCompatActivity {

    @NotNull
    public static Integer numb = 1000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initDatabase();
    }

    private void initView() {
        ComposeView composeView =(ComposeView) findViewById(R.id.compose_view);
        TestShowUi.setContent(composeView);
    }

    private void initDatabase() {
        //创建数据库
        Connector.getDatabase();
        //插入数据
        //插入第一条数据
        for (int i = 0;i < 10;i ++){
        HistoryRecord historyRecord = new HistoryRecord("1"+i,"2"+i,"3"+i,"4"+i);
        historyRecord.save();
        }

        //查询
        //查询所有记录
        LitePal.deleteAll(HistoryRecord.class);
        List<HistoryRecord> list = LitePal.where(" id  > 50 order by id desc ").find(HistoryRecord.class);
        list.forEach(s ->{
            Log.d("=====>list", "value: "+s.device_name);

        });
        HistoryRecord hi = new HistoryRecord("","","","");
       int i =  hi.delete();

    }

    public void showToast(Object application){
        application = (Application)application;
        Toast.makeText(((Application) application).getBaseContext(), "我改变了数值了" + numb, Toast.LENGTH_SHORT).show();
        Log.d("TAG", "showToast:=========================> ");
    }
}